package com.jone.bang.service;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.jone.bang.HomeActivity;
import com.jone.bang.R;
import com.jone.bang.db.ConfigCenter;
import com.jone.bang.util.Constant;

public class MyNotification extends BroadcastReceiver{
	
	private DownloadService downloadService;
	
	@Override
	public void onReceive(Context context, Intent intent) {
		if(downloadService == null){
			downloadService = new DownloadService(context);
		}
	     //执行方法体，实现业务逻辑
		if(ConfigCenter.getValue(context, Constant.KEY_ENABLE_NOTIFICATION, true)){
			String items = downloadService.getNotificationString(Constant.TOP_SEARCH_TODAY);
			if(!"".equals(items)){
				showNotify(context,items);
			}
		}
	}
	
	private void showNotify(Context context,String items){
		NotificationManager nfManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
		Notification nf = new Notification();
		nf.icon = R.drawable.icon32;
		nf.defaults = Notification.DEFAULT_SOUND;
		PendingIntent contentIntent = PendingIntent
				.getActivity(context, 0, new Intent(context,HomeActivity.class), 0);
		nf.setLatestEventInfo(context, "今日飙升热搜", items ,contentIntent);
		nf.flags = Notification.FLAG_NO_CLEAR;

		nfManager.notify(118, nf);
	}

}
